<?php 
switch($ts){
	case "add":
		
		include TmooTemplate("ajax_add");
		break;
		
	case "add_do":
	
		$userid = intval($TS_USER['user']['userid']);
		if($userid == '0') qiMsg("非法操作！");
	
		if($_FILES['attach']['name'][0] == '') qiMsg("上传文件不能为空！");
		
		//处理目录存储方式
		$menu = substr($userid,0,1);
		
		$date = date('Ymd');
		
		$dest_dir='data/uploadfile/attach/'.$menu.'/'.$date.'/'.$userid;
		createFolders($dest_dir);
		
		if(isset($_FILES['attach'])){
			$arrFileName = $_FILES['attach']['name'];
			foreach($arrFileName as $key=>$item){
				if($item != ''){
					$attachname = $item;
					$attachtype = $_FILES['attach']['type'][$key];
					$attachsize = $_FILES['attach']['size'][$key];
					
					$dest=$dest_dir.'/'.$item;
					move_uploaded_file($_FILES['attach']['tmp_name'][$key], iconv("UTF-8","gb2312",$dest));
					chmod($dest, 0755);
					
					$attachurl = $date.'/'.$userid.'/'.$item;
					
					$arrData = array(
						'userid'	=> $userid,
						'attachname'	=> $attachname,
						'attachtype'	=> $attachtype,
						'attachurl'		=> $attachurl,
						'attachsize'		=> $attachsize,
						'addtime'	=> time(),
					);
					
					$attachid = $DB->insertArr($arrData,'app_attach');
					
				}
				
			}
		}
		
		header("Location: index.php?app=attach&ac=ajax&ts=my");
	
		break;
		
	case "flash":
		include TmooTemplate("ajax_flash");
		break;
		
	case "flash_do":
		break;
		
	case "my":
		$userid = intval($TS_USER['user']['userid']);
		
		$arrAttach = $DB->fetch_all_assoc("select * from ".dbprefix."app_attach where userid='$userid'");
		
		include TmooTemplate("ajax_my");
		break;
	
	//下载 
	case "down":
		$attachid = $_GET['attachid'];
		
		$strAttach = $DB->once_fetch_assoc("select * from ".dbprefix."app_attach where attachid='$attachid'");
		
		$menu = substr($strAttach['userid'],0,1);

		$strAttach['attachurl'] = 'data/uploadfile/attach/'.$menu.'/'.$strAttach['attachurl'];
		
		header("Location: ".$strAttach['attachurl']);
		
		break;
}